package com.ruoyi.fsepc.service.impl;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.fsepc.domain.StFseLocation;
import com.ruoyi.fsepc.mapper.StFseLocationMapper;
import com.ruoyi.fsepc.service.IStFseLocationService;
import com.ruoyi.system.api.domain.User;
import com.ruoyi.system.api.mapper.UserMapper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * FSE实时位置坐标Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-02-27
 */
@Service
public class StFseLocationServiceImpl implements IStFseLocationService
{
	private static final Logger log = LoggerFactory.getLogger(StFseLocationServiceImpl.class);
	
    @Autowired
    private StFseLocationMapper stFseLocationMapper;

    @Autowired
    private UserMapper userMapper;
    
    /**
     * 查询FSE实时位置坐标
     * 
     * @param id FSE实时位置坐标ID
     * @return FSE实时位置坐标
     */
    @Override
    public StFseLocation selectStFseLocationById(Long id)
    {
        return stFseLocationMapper.selectStFseLocationById(id);
    }

    /**
     * 查询FSE实时位置坐标列表
     * 
     * @param stFseLocation FSE实时位置坐标
     * @return FSE实时位置坐标
     */
    @Override
    public List<StFseLocation> selectStFseLocationList(StFseLocation stFseLocation)
    {
        return stFseLocationMapper.selectStFseLocationList(stFseLocation);
    }

    /**
     * 新增FSE实时位置坐标
     * 
     * @param stFseLocation FSE实时位置坐标
     * @return 结果
     */
    @Override
    public int insertStFseLocation(StFseLocation stFseLocation)
    {
    	User user = new User();
        user.setEnginnerId(Long.parseLong(stFseLocation.getFseId()));
        List<User> users = userMapper.selectUserList(user);
        boolean isWorkDay=false;
        if(users!=null && users.size()>0 ){
            String workDay = "0";
            if(workDay.equals(users.get(0).getWorkday())){
            	isWorkDay=true;
            }
        }
        
        //当用户在工作时间内，正常上班状态下，才进行定位入库
    	stFseLocation.setCreateTime(DateUtils.getNowDate());
    	return stFseLocationMapper.insertStFseLocation(stFseLocation);
        
    }

    /**
     * 修改FSE实时位置坐标
     * 
     * @param stFseLocation FSE实时位置坐标
     * @return 结果
     */
    @Override
    public int updateStFseLocation(StFseLocation stFseLocation)
    {
        stFseLocation.setUpdateTime(DateUtils.getNowDate());
        return stFseLocationMapper.updateStFseLocation(stFseLocation);
    }

    /**
     * 删除FSE实时位置坐标对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteStFseLocationByIds(String ids)
    {
        return stFseLocationMapper.deleteStFseLocationByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除FSE实时位置坐标信息
     * 
     * @param id FSE实时位置坐标ID
     * @return 结果
     */
    @Override
    public int deleteStFseLocationById(Long id)
    {
        return stFseLocationMapper.deleteStFseLocationById(id);
    }

    /**
     *
     * @param fseId
     * @return
     */
    @Override
    public List<StFseLocation> selectListByFseId(String fseId) {
        return stFseLocationMapper.selectListByFseId(Convert.toStrArray(fseId));
    }

    /**
     * FSE全量实时查询
     * @param fseLocation
     * @return
     */
    @Override
    public List<StFseLocation> getFseLocation(StFseLocation fseLocation) {
        return stFseLocationMapper.getFseLocation(fseLocation);
    }
    
    /**
     * 
     * @param fseLocation
     * @return
     */
    public List<StFseLocation> getStFseLocation(StFseLocation fseLocation){
    	 return stFseLocationMapper.getStFseLocation(fseLocation);
    }
    
}
